package com.go.where.family.component.impl;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.internal.util.AlipaySignature;
import com.alipay.api.request.AlipayTradeRefundRequest;
import com.alipay.api.response.AlipayTradeRefundResponse;
import com.go.where.family.component.OrderComponent;
import com.go.where.family.constants.Constant;
import com.go.where.family.constants.TransmissionCode;
import com.go.where.family.exception.ServerDisponseException;
import com.go.where.family.pojo.ActivityInfo;
import com.go.where.family.pojo.ActivitySignupInfo;
import com.go.where.family.pojo.CourseInfo;
import com.go.where.family.pojo.CustomerInfo;
import com.go.where.family.pojo.GroupInfo;
import com.go.where.family.pojo.OrderInfo;
import com.go.where.family.scoket.Head;
import com.go.where.family.service.ActivityService;
import com.go.where.family.service.CourseService;
import com.go.where.family.service.CustomerService;
import com.go.where.family.service.GroupService;
import com.go.where.family.service.OrderService;
import com.go.where.family.utils.CommonUtil;
import com.go.where.family.utils.DateUtil;
import com.go.where.family.utils.IDGenerater;
import com.go.where.family.utils.MD5Util;
import com.go.where.family.utils.ParseWeichatXml;
import com.go.where.family.vo.ActivitySignupVo;
import com.go.where.family.vo.AlipayVo;
import com.go.where.family.vo.GroupVo;
import com.go.where.family.vo.OrderVo;
import com.go.where.family.vo.WeichatVo;
import com.google.gson.Gson;

@Component("orderComponent")
public class OrderComponentImpl implements OrderComponent {

	private static final Logger log = Logger
			.getLogger(OrderComponentImpl.class);
	private static final ExecutorService refundThread = Executors
			.newFixedThreadPool(20);
	private Gson gson;
	@Resource(name = "orderService")
	private OrderService orderService;
	@Resource(name = "groupService")
	private GroupService groupService;
	@Resource(name = "activityService")
	private ActivityService activityService;
	@Resource(name = "customerService")
	private CustomerService customerService;
	@Resource(name = "courseService")
	private CourseService courseService;

	public OrderComponentImpl() {
		gson = CommonUtil.gson();
	}

	@Override
	public List<OrderInfo> queryList(String body, Head head) {
		OrderVo vo = gson.fromJson(body, OrderVo.class);
		if (vo != null) {
			Integer currentPage = vo.getPageIndex();
			Integer pageSize = vo.getPageCount();
			Integer pageStart = 1;
			Integer pageEnd = 10;
			if (currentPage != null && pageSize != null) {
				pageStart = (currentPage - 1) * pageSize + 1;
				pageEnd = currentPage * pageSize;
			}
			List<String> orderIds = groupService.queryByCustomerId(vo
					.getCustomerId());
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("pageStart", pageStart);
			map.put("pageEnd", pageEnd);
			map.put("customerId", vo.getCustomerId());
			map.put("payStatus", vo.getPayStatus());
			map.put("payType", vo.getPayType());
			// map.put("activityType", "2");
			if (orderIds != null && !orderIds.isEmpty()) {
				map.put("orderIds", orderIds);
			}
			map.put("isDelete", Constant.IS_NOT_DELETE);

			List<OrderInfo> list = orderService.queryList(map);
			if (list != null && !list.isEmpty()) {
				return list;
			} else {
				return new ArrayList<OrderInfo>();
			}
		} else {
			log.info("requestId:" + head.getRequestId()
					+ ",获取购买订单列表信息时，参数报文解析异常。");
			throw new ServerDisponseException(TransmissionCode.ERROR_ADJUST
					.getCode(), TransmissionCode.ERROR_ADJUST.getMessage());
		}
	}

	@Override
	public List<OrderInfo> queryGroupList(String body, Head head) {
		OrderVo vo = gson.fromJson(body, OrderVo.class);
		if (vo != null) {
			Integer currentPage = vo.getPageIndex();
			Integer pageSize = vo.getPageCount();
			Integer pageStart = 1;
			Integer pageEnd = 10;
			if (currentPage != null && pageSize != null) {
				pageStart = (currentPage - 1) * pageSize + 1;
				pageEnd = currentPage * pageSize;
			}
			List<String> orderIds = groupService.queryByCustomerId(vo
					.getCustomerId());
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("pageStart", pageStart);
			map.put("pageEnd", pageEnd);
			map.put("payStatus", vo.getPayStatus());
			map.put("payType", vo.getPayType());
			map.put("customerId", vo.getCustomerId());
			// map.put("activityType", "2");
			if (orderIds != null && !orderIds.isEmpty()) {
				map.put("groupOrderIds", orderIds);
			}
			map.put("isDelete", Constant.IS_NOT_DELETE);

			List<OrderInfo> list = orderService.queryList(map);
			if (list != null && !list.isEmpty()) {
				return list;
			} else {
				return new ArrayList<OrderInfo>();
			}
		} else {
			log.info("requestId:" + head.getRequestId()
					+ ",获取团购订单列表信息时，参数报文解析异常。");
			throw new ServerDisponseException(TransmissionCode.ERROR_ADJUST
					.getCode(), TransmissionCode.ERROR_ADJUST.getMessage());
		}
	}

	@Override
	public OrderVo saveSignup(String body, Head head) {
		ActivitySignupVo vo = gson.fromJson(body, ActivitySignupVo.class);
		if (vo != null) {
			if (vo.getPersonNum() == null || vo.getPersonNum() == 0) {
				log.info("requestId:" + head.getRequestId()
						+ ",活动报名时，报名人数为空,活动ID：" + vo.getActivityId());
				throw new ServerDisponseException(
						TransmissionCode.SIGN_PERSON_IS_NULL.getCode(),
						TransmissionCode.SIGN_PERSON_IS_NULL.getMessage());
			}
			ActivitySignupInfo signup = new ActivitySignupInfo();
			signup.setActivityId(vo.getActivityId());
			signup.setCourseId(vo.getCourseId());
			signup.setActivityTitle(vo.getActivityTitle());
			signup.setActivityType(vo.getActivityType());
			signup.setCustomerId(vo.getCustomerId());
			signup.setCustomerName(vo.getCustomerName());
			signup.setMobile(vo.getMobile());
			signup.setPersonNum(vo.getPersonNum());
			ActivityInfo act = null;
			if (StringUtils.isNotBlank(vo.getActivityId())) {
				act = activityService.queryActivityDetail(vo.getActivityId());
			}
			CourseInfo courseInfo = null;
			if (StringUtils.isNotBlank(vo.getCourseId())) {
				courseInfo = courseService.queryCourseDetail(vo.getCourseId());
			}
			CustomerInfo customerInfo = customerService.queryByPrimaryKey(vo
					.getCustomerId(), head);
			BigDecimal activityPrice = new BigDecimal(0);
			int level = CommonUtil.getCustomerLevel(customerInfo
					.getCustomerScore());
			if (act != null) {
				if (level <= 0) {
					activityPrice = act.getOriginalPrice();
				} else {
					activityPrice = act.getPreferentialPrice();
				}
				Integer partakeNum = act.getPartakeNum();
				partakeNum = CommonUtil.add(partakeNum, 1);
				ActivityInfo info = new ActivityInfo();
				info.setActivityId(vo.getActivityId());
				info.setPartakeNum(partakeNum);
				activityService.update(info);
			} else if (courseInfo != null) {
				if (level <= 0) {
					activityPrice = courseInfo.getOriginalPrice();
				} else {
					activityPrice = courseInfo.getPreferentialPrice();
				}
			} else {
				log.info("requestId:" + head.getRequestId()
						+ ",活动报名时，没有此活动,活动ID：" + vo.getActivityId());
				throw new ServerDisponseException(TransmissionCode.NO_DATA
						.getCode(), TransmissionCode.NO_DATA.getMessage());
			}
			BigDecimal orderAmount = CommonUtil.multiply(activityPrice, vo
					.getPersonNum());
			OrderVo order = new OrderVo();
			order.setActivityId(vo.getActivityId());
			order.setOrderAmount(orderAmount);
			order.setCourseId(vo.getCourseId());
			order.setCustomerId(vo.getCustomerId());
			order.setActivityType(vo.getActivityType());
			order.setGroupId(vo.getGroupId());
			order.setPersonNum(vo.getPersonNum());
			OrderVo orderVo = null;
			if (Constant.ACTIVITY_TYPE_GROUP.equals(vo.getActivityType())) {
				orderVo = groupPay(CommonUtil.gson().toJson(order), head);
			} else {
				orderVo = directPay(CommonUtil.gson().toJson(order), head);
			}
			if (orderVo != null) {
				Integer totalScore = 0;
				if (customerInfo != null) {
					totalScore = customerInfo.getCustomerScore();
				}
				if (act != null
						&& Constant.ACTIVITY_TYPE_FREE.equals(act
								.getActivityType())) {
					if (!CommonUtil
							.compare(
									totalScore,
									CommonUtil
											.multiply(
													new BigDecimal(
															Constant.FREE_ACTIVITY_SIGN_UP_SCORE),
													vo.getPersonNum())
											.intValue())) {
						throw new ServerDisponseException(
								TransmissionCode.NO_MORE_SCORE.getCode(),
								TransmissionCode.NO_MORE_SCORE.getMessage());
					} else {
						synchronized (this) {
							// 扣除客户积分
							int afterScore = CommonUtil
									.sub(
											totalScore,
											CommonUtil
													.multiply(
															new BigDecimal(
																	Constant.FREE_ACTIVITY_SIGN_UP_SCORE),
															vo.getPersonNum())
													.intValue());
							CustomerInfo ci = new CustomerInfo();
							ci.setCustomerId(vo.getCustomerId());
							ci.setCustomerScore(afterScore);
							customerService.update(ci, head);
						}
					}
				}
				activityService.saveSignup(signup);
			}
			return orderVo;

		} else {
			log.info("requestId:" + head.getRequestId()
					+ ",保存活动报名信息时，参数报文解析异常。");
			throw new ServerDisponseException(TransmissionCode.ERROR_ADJUST
					.getCode(), TransmissionCode.ERROR_ADJUST.getMessage());
		}
	}

	@Override
	public OrderVo directPay(String body, Head head) {
		OrderVo vo = gson.fromJson(body, OrderVo.class);
		if (vo != null) {
			String customerId = vo.getCustomerId();
			String activityId = vo.getActivityId();
			String courseId = vo.getCourseId();
			String activityType = "";
			ActivityInfo activityInfo = null;
			CourseInfo courseInfo = null;
			Date activityEnd = null;
			Integer stock = 0;
			if (StringUtils.isNotBlank(activityId)) {
				activityInfo = activityService.queryActivityDetail(activityId);
				activityType = activityInfo.getActivityType();
				if (StringUtils.isBlank(activityType)) {
					activityInfo.setActivityType(vo.getActivityType());
				}
				activityEnd = activityInfo.getEndTime();
				stock = activityInfo.getStock();
				if (CommonUtil.compare(vo.getPersonNum(), stock)) {
					log.info("requestId:" + head.getRequestId()
							+ ",购买失败，活动库存不足。活动id：" + activityId + "。");
					throw new ServerDisponseException(
							TransmissionCode.ACTIVITY_STOCK_NO_MORE.getCode(),
							TransmissionCode.ACTIVITY_STOCK_NO_MORE
									.getMessage());
				}
			}
			if (StringUtils.isNotBlank(courseId)) {
				activityType = Constant.ACTIVITY_TYPE_BUY;
				courseInfo = courseService.queryCourseDetail(courseId);
				activityEnd = courseInfo.getCourseEndTime();
				stock = courseInfo.getCourseLimit();
				// Map<String,Object> map = new HashMap<String,Object>();
				// map.put("courseId", courseId);
				// Integer totalPerson = orderService.sumPersonNum(map);
				if (CommonUtil.compare(vo.getPersonNum(), stock)) {
					log.info("requestId:" + head.getRequestId()
							+ ",购买失败，课程库存不足。课程id：" + courseId + "。");
					throw new ServerDisponseException(
							TransmissionCode.ACTIVITY_STOCK_NO_MORE.getCode(),
							TransmissionCode.ACTIVITY_STOCK_NO_MORE
									.getMessage());
				}
			}
			Date currentDate = new Date();
			if (activityEnd != null && currentDate.after(activityEnd)) {
				log.info("requestId:" + head.getRequestId()
						+ ",购买失败，活动有效时间已到。活动id：" + activityId + "。");
				throw new ServerDisponseException(
						TransmissionCode.ACTIVITY_TIME_FINISHED.getCode(),
						TransmissionCode.ACTIVITY_TIME_FINISHED.getMessage());
			}
			CustomerInfo customerInfo = customerService.queryByPrimaryKey(
					customerId, head);

			String orderId = IDGenerater.getInstance().getOrderNo(
					"OrderComponentImpl");
			Integer totalScore = customerInfo.getCustomerScore();
			if (Constant.ACTIVITY_TYPE_BUY.equals(activityType)) {
				// 根据购买金额获取对应积分
				BigDecimal orderAmount = vo.getOrderAmount();
				synchronized (this) {
					BigDecimal scoreTemp = orderAmount.multiply(
							new BigDecimal(Constant.GET_SCORE_OF_BUY))
							.setScale(0, BigDecimal.ROUND_HALF_UP);
					int score = CommonUtil
							.add(totalScore, scoreTemp.intValue());
					CustomerInfo ci = new CustomerInfo();
					ci.setCustomerId(customerId);
					ci.setCustomerScore(score);
					customerService.update(ci, head);
				}
			}
			OrderInfo orderInfo = createOrder(vo, customerId, activityInfo,
					courseInfo, orderId, stock);

			int orderResult = orderService.save(orderInfo);
			if (orderResult > 0) {
				OrderVo ovo = new OrderVo();
				ovo.setOrderId(orderId);
				ovo.setActivityId(activityId);
				ovo.setCourseId(courseId);
				ovo.setCustomerId(customerId);
				if (activityInfo != null) {
					ovo.setOrderTitle(activityInfo.getActivityTitle());
					ovo.setOrderDetail(activityInfo.getActivityTitle());
				} else {
					ovo.setOrderTitle(courseInfo.getCourseName());
					ovo.setOrderDetail(courseInfo.getCourseName());
				}
				ovo.setOrderAmount(orderInfo.getOrderAmount());
				ovo.setOrderTime(orderInfo.getOrderTime());
				ovo.setOrderStatus(orderInfo.getOrderStatus());
				ovo.setPayStatus(orderInfo.getPayStatus());
				return ovo;
			} else {
				log.info("requestId:" + head.getRequestId() + ",直接购买时，创建订单异常。");
				throw new ServerDisponseException(
						TransmissionCode.OPERATOR_EXCEPTION.getCode(),
						TransmissionCode.OPERATOR_EXCEPTION.getMessage());
			}

		} else {
			log.info("requestId:" + head.getRequestId() + ",直接购买时，参数报文解析异常。");
			throw new ServerDisponseException(TransmissionCode.ERROR_ADJUST
					.getCode(), TransmissionCode.ERROR_ADJUST.getMessage());
		}
	}

	@Override
	public synchronized OrderVo groupPay(String body, Head head) {
		OrderVo vo = gson.fromJson(body, OrderVo.class);
		if (vo != null) {
			String customerId = vo.getCustomerId();
			String activityId = vo.getActivityId();
			String courseId = vo.getCourseId();
			ActivityInfo activityInfo = null;
			Integer stock = 0;
			if (StringUtils.isNotBlank(activityId)) {
				activityInfo = activityService.queryActivityDetail(activityId);
				stock = activityInfo.getStock();
				if (CommonUtil.compare(vo.getPersonNum(), stock)) {
					log.info("requestId:" + head.getRequestId()
							+ ",团购购买失败，活动库存不足。活动id：" + activityId + "。");
					throw new ServerDisponseException(
							TransmissionCode.ACTIVITY_STOCK_NO_MORE.getCode(),
							TransmissionCode.ACTIVITY_STOCK_NO_MORE
									.getMessage());
				}
			}
			String orderId = IDGenerater.getInstance().getOrderNo(
					"OrderComponentImpl");
			// 校验团购有效期，在规定时间内有没有达到指定人数
			// 团购人数
			Date activityEnd = activityInfo.getEndTime();
			long effective = 0;
			Date currentDate = new Date();
			GroupInfo gi = new GroupInfo();
			if (StringUtils.isNotBlank(vo.getGroupId())) {
				// 说明此团已开
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("groupId", vo.getGroupId());
				// List<GroupInfo> gList = groupService.queryByParameters(map);
				// int groupSize = gList.size();
				Integer groupSize = groupService.queryGroupTotalPerson(map);
				if (groupSize == null) {
					groupSize = 0;
				}
				if (currentDate.after(activityEnd)) {
					GroupInfo g = new GroupInfo();
					g.setGroupId(vo.getGroupId());
					if (groupSize < activityInfo.getGroupPeoples()) {
						g.setGroupStatus("0");
						groupService.update(g);
						// 失败，退款
						refund(vo.getGroupId(), head);
						log.info("requestId:" + head.getRequestId()
								+ ",团购失败，团购有效时间已到，团购人数未满。活动id：" + activityId
								+ ",团购id：" + vo.getGroupId());
						throw new ServerDisponseException(
								TransmissionCode.ACTIVITY_TIME_FINISHED
										.getCode(),
								TransmissionCode.ACTIVITY_TIME_FINISHED
										.getMessage());
					} else {
						g.setGroupStatus("1");
						groupService.update(g);
						log.info("requestId:" + head.getRequestId()
								+ ",团购成功，团购有效时间已到，团购人数已到。活动id：" + activityId
								+ ",团购id：" + vo.getGroupId());
					}
				} else {
					if (groupSize <= activityInfo.getGroupPeoples()) {
						// 记录团购信息
						GroupInfo group = new GroupInfo();
						group.setActivityId(activityId);
						group.setOrderId(orderId);
						group.setCustomerId(customerId);
						group.setGroupId(vo.getGroupId());
						effective = DateUtil.secondBetween(new Date(),
								activityEnd);
						group.setGroupEffectiveTime(effective);
						group.setPersonNum(vo.getPersonNum());
						gi = groupService.save(group);
					} else {
						// 团购人数已满，此次操作失败
						log.info("requestId:" + head.getRequestId()
								+ ",团购有效时间内，团购人数已到，此次操作失败。");
						throw new ServerDisponseException(
								TransmissionCode.GROUP_FAILED.getCode(),
								TransmissionCode.GROUP_FAILED.getMessage());
					}
				}

			} else {
				if (currentDate.after(activityEnd)) {
					// 失败，未开团
					log.info("requestId:" + head.getRequestId()
							+ ",团购失败，团购有效时间已到，未开团。活动id：" + activityId);
					throw new ServerDisponseException(
							TransmissionCode.ACTIVITY_TIME_FINISHED.getCode(),
							TransmissionCode.ACTIVITY_TIME_FINISHED
									.getMessage());
				} else {
					if (activityInfo.getGroupPeoples() < vo.getPersonNum()) {
						log.info("requestId:" + head.getRequestId()
								+ ",团购失败，开团时人数超限。活动id：" + activityId);
						throw new ServerDisponseException(
								TransmissionCode.GROUP_PEOPLES_MORE_THAN_LIMIT
										.getCode(),
								TransmissionCode.GROUP_PEOPLES_MORE_THAN_LIMIT
										.getMessage());
					}
					// 记录团购信息
					GroupInfo group = new GroupInfo();
					group.setActivityId(activityId);
					group.setOrderId(orderId);
					group.setCustomerId(customerId);
					group.setGroupId(groupService.getNextKey());
					effective = DateUtil.secondBetween(new Date(), activityEnd);
					group.setGroupEffectiveTime(effective);
					group.setPersonNum(vo.getPersonNum());
					gi = groupService.save(group);
				}
			}

			OrderInfo orderInfo = createOrder(vo, customerId, activityInfo,
					null, orderId, stock);
			int orderResult = orderService.save(orderInfo);
			if (orderResult > 0) {
				OrderVo ovo = new OrderVo();
				ovo.setOrderId(orderId);
				ovo.setGroupId(gi.getGroupId());
				ovo.setGroupEffectiveTime(gi.getGroupEffectiveTime());
				ovo.setActivityId(activityId);
				ovo.setCourseId(courseId);
				ovo.setCustomerId(customerId);
				ovo.setOrderTitle(activityInfo.getActivityTitle());
				ovo.setOrderDetail(activityInfo.getActivityTitle());
				ovo.setOrderAmount(orderInfo.getOrderAmount());
				ovo.setOrderTime(orderInfo.getOrderTime());
				ovo.setOrderStatus(orderInfo.getOrderStatus());
				ovo.setPayStatus(orderInfo.getPayStatus());
				return ovo;
			} else {
				log.info("requestId:" + head.getRequestId() + ",团购时，创建订单异常。");
				throw new ServerDisponseException(
						TransmissionCode.OPERATOR_EXCEPTION.getCode(),
						TransmissionCode.OPERATOR_EXCEPTION.getMessage());
			}
		} else {
			log.info("requestId:" + head.getRequestId() + ",团购时，参数报文解析异常。");
			throw new ServerDisponseException(TransmissionCode.ERROR_ADJUST
					.getCode(), TransmissionCode.ERROR_ADJUST.getMessage());
		}
	}

	@Override
	public OrderInfo queryOrderDetail(String body, Head head) {
		OrderVo vo = gson.fromJson(body, OrderVo.class);
		if (vo != null) {
			String orderId = vo.getOrderId();
			OrderInfo oo = orderService.queryOrderDetail(orderId);
			if (oo != null) {
				return oo;
			} else {
				log.info("requestId:" + head.getRequestId()
						+ ",获取订单详情时，没有获得数据。订单Id：" + orderId);
				throw new ServerDisponseException(TransmissionCode.NO_DATA
						.getCode(), TransmissionCode.NO_DATA.getMessage());
			}
		} else {
			log.info("requestId:" + head.getRequestId() + ",获取订单详情时，参数报文解析异常。");
			throw new ServerDisponseException(TransmissionCode.ERROR_ADJUST
					.getCode(), TransmissionCode.ERROR_ADJUST.getMessage());
		}
	}

	@Override
	public boolean update(String body, Head head) {
		OrderVo vo = gson.fromJson(body, OrderVo.class);
		if (vo != null) {
			int re = 0;
			String orderId = vo.getOrderId();
			OrderInfo oo = new OrderInfo();
			oo.setOrderId(orderId);
			oo.setTpPayNo(vo.getTpPayNo());
			OrderInfo info = orderService.queryOrderDetail(orderId);
			if (info == null) {
				log.info("requestId:" + head.getRequestId()
						+ ",异步通知更新订单状态时，无此订单信息，更新失败。订单Id：" + orderId);
				return false;
			}
			if (Constant.PAY_TYPE_ALIPAY.equals(vo.getPayType())) {
				// if (!CommonUtil.getProperties("alipay.app.id").equals(appId))
				// {
				// log.info("requestId:" + head.getRequestId()
				// + ",异步通知更新订单状态时，应用id不相同，更新失败。订单Id：" + orderId);
				// return false;
				// }
				// BigDecimal orderAmount = info.getOrderAmount().setScale(2);
				// if (!orderAmount.equals(new BigDecimal(vo.getTotalAmount())))
				// {
				// log.info("requestId:" + head.getRequestId()
				// + ",异步通知更新订单状态时，订单金额不符，更新失败。订单Id：" + orderId
				// + "本地金额：" + orderAmount + ",支付宝通知金额"
				// + vo.getTotalAmount());
				// return false;
				// }
				oo.setPayType(Constant.PAY_TYPE_ALIPAY);
				if ("TRADE_SUCCESS".equals(vo.getTradeStatus())
						|| "TRADE_FINISHED".equals(vo.getTradeStatus())) {
					oo.setOrderStatus(Constant.ORDER_STATUS_SUCCESS);
					oo.setPayStatus(Constant.PAY_STATUS_PAYED);
					re = orderService.update(oo);
				}
				if ("TRADE_CLOSED".equals(vo.getTradeStatus())) {
					oo.setOrderStatus(Constant.ORDER_STATUS_CANCEL);
					oo.setPayStatus(Constant.PAY_STATUS_PAY_FAILED);
					re = orderService.update(oo);
				}
			} else if (Constant.PAY_TYPE_WECHAT.equals(vo.getPayType())) {
				if ("SUCCESS".equals(vo.getTradeStatus())) {
					oo.setOrderStatus(Constant.ORDER_STATUS_SUCCESS);
					oo.setPayStatus(Constant.PAY_STATUS_PAYED);
				} else if ("FAIL".equals(vo.getTradeStatus())) {
					oo.setOrderStatus(Constant.ORDER_STATUS_FAILED);
					oo.setPayStatus(Constant.PAY_STATUS_PAY_FAILED);
				}
				oo.setPayType(Constant.PAY_TYPE_WECHAT);
				re = orderService.update(oo);
			} else {
				oo.setOrderStatus(vo.getOrderStatus());
				re = orderService.update(oo);
			}

			if (re > 0) {
				return true;
			} else {
				log.info("requestId:" + head.getRequestId()
						+ ",异步通知更新订单状态时，没有成功。订单Id：" + orderId);
				return false;
			}
		} else {
			log.info("requestId:" + head.getRequestId() + ",更新订单时，参数报文解析异常。");
			throw new ServerDisponseException(TransmissionCode.ERROR_ADJUST
					.getCode(), TransmissionCode.ERROR_ADJUST.getMessage());
		}
	}

	@Override
	public boolean delete(String body, Head head) {
		OrderVo vo = gson.fromJson(body, OrderVo.class);
		if (vo != null) {
			String orderId = vo.getOrderId();
			OrderInfo oo = new OrderInfo();
			oo.setOrderId(orderId);
			oo.setCustomerId(vo.getCustomerId());
			oo.setIsDelete(Constant.IS_DELETE);
			int re = orderService.update(oo);
			if (re > 0) {
				return true;
			} else {
				log.info("requestId:" + head.getRequestId() + ",删除订单没有成功。订单Id："
						+ orderId);
				return false;
			}
		} else {
			log.info("requestId:" + head.getRequestId() + ",更新订单时，参数报文解析异常。");
			throw new ServerDisponseException(TransmissionCode.ERROR_ADJUST
					.getCode(), TransmissionCode.ERROR_ADJUST.getMessage());
		}
	}

	@Override
	public String sign3PartOrderInfo(String body, Head head) {
		OrderVo vo = gson.fromJson(body, OrderVo.class);
		if (vo != null) {
			String orderId = vo.getOrderId();
			String payType = vo.getPayType();
			String orderInfoStr = "";
			OrderInfo orderInfo = orderService.queryOrderDetail(orderId);
			if (orderInfo != null) {
				String courseId = orderInfo.getCourseId();
				if (StringUtils.isNotBlank(courseId)) {
					CourseInfo ci = courseService.queryCourseDetail(courseId);
					orderInfo.setActivityTitle(ci.getCourseName());
				}
				if (StringUtils.isNotBlank(orderInfo.getActivityId())) {
					ActivityInfo ai = activityService
							.queryActivityDetail(orderInfo.getActivityId());
					orderInfo.setActivityTitle(ai.getActivityTitle());
				}
				OrderInfo oo = new OrderInfo();
				oo.setOrderId(orderId);
				if (Constant.PAY_TYPE_ALIPAY.equals(payType)) {
					oo.setPayType(Constant.PAY_TYPE_ALIPAY);
					orderInfoStr = signAlipayOrderInfo(orderInfo);
				} else {
					oo.setPayType(Constant.PAY_TYPE_WECHAT);
					orderInfoStr = weichatOrderInfo(orderInfo);
				}
				orderService.update(oo);
			}
			return orderInfoStr;
		} else {
			log.info("requestId:" + head.getRequestId()
					+ "根据本地订单信息，拼接发送到第三方支付平台的支付信息及签名字符串时，参数报文解析异常。");
			throw new ServerDisponseException(TransmissionCode.ERROR_ADJUST
					.getCode(), TransmissionCode.ERROR_ADJUST.getMessage());
		}
	}

	@Override
	public GroupVo queryAllGroupInfo(String body, Head head) {
		OrderVo vo = gson.fromJson(body, OrderVo.class);
		if (vo != null) {
			String activityId = vo.getActivityId();
			GroupInfo gi = new GroupInfo();
			gi.setActivityId(activityId);
			ActivityInfo ai = activityService.queryActivityDetail(activityId);
			Date endTime = null;
			int totalPeoples = 0;
			if (ai != null) {
				endTime = ai.getEndTime();
				totalPeoples = ai.getGroupPeoples();
			}
			GroupVo gv = new GroupVo();
			gv.setActivityId(activityId);
			gv.setEndTime(endTime);
			gv.setTotalPeoples(totalPeoples);
			List<GroupInfo> gList = groupService.queryByActivityId(gi);
			if (gList != null && !gList.isEmpty()) {
				for (GroupInfo gin : gList) {
					Map<String, Object> map = new HashMap<String, Object>();
					map.put("activityId", gin.getActivityId());
					map.put("groupId", gin.getGroupId());
					// int currentPeoples = groupService.queryCount(map);
					Integer currentPeoples = groupService
							.queryGroupTotalPerson(map);
					if (currentPeoples != null) {
						gin.setCurrentPeoples(currentPeoples);
					}
					List<String> customerIds = groupService
							.queryCustomerIds(gin);
					if (customerIds != null && !customerIds.isEmpty()) {
						Map<String, Object> para = new HashMap<String, Object>();
						para.put("customerIds", customerIds);
						List<CustomerInfo> customerList = customerService
								.getUserListByUserIds(para);
						if (customerList != null && !customerList.isEmpty()) {
							for (CustomerInfo ci : customerList) {
								ci.setHeaderPath(CommonUtil.getUrlPrefix()
										+ ci.getHeaderPath());
							}
							gin.setCustomerList(customerList);
						}
					}
				}

				gv.setGroupList(gList);
				return gv;
			} else {
				return new GroupVo();
			}
		} else {
			log.info("requestId:" + head.getRequestId()
					+ ",获取所有团购信息时，参数报文解析异常。");
			throw new ServerDisponseException(TransmissionCode.ERROR_ADJUST
					.getCode(), TransmissionCode.ERROR_ADJUST.getMessage());
		}
	}

	private void refund(final String groupId, final Head head) {
		refundThread.execute(new Runnable() {
			@Override
			public void run() {
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("groupId", groupId);
				List<GroupInfo> gList = groupService.queryByParameters(map);
				if (gList != null && !gList.isEmpty()) {
					for (GroupInfo g : gList) {
						String orderId = g.getOrderId();
						OrderInfo orderInfo = orderService
								.queryOrderDetail(orderId);
						if (orderInfo != null
								&& Constant.ORDER_STATUS_SUCCESS
										.equals(orderInfo.getOrderStatus())) {
							String payType = orderInfo.getPayType();
							if (Constant.PAY_TYPE_ALIPAY.equals(payType)) {
								alipayRefund(orderId, orderInfo
										.getOrderAmount(), head);
							} else if (Constant.PAY_TYPE_WECHAT.equals(payType)) {
								// 暂时没有实现
							}
						}
						try {
							Thread.sleep(2000);
						} catch (InterruptedException e) {
							log.error("", e);
						}
					}
				}
			}
		});
	}

	public static void main(String[] args) {
		OrderComponentImpl o = new OrderComponentImpl();
		Head head = new Head();
		head.setRequestId(UUID.randomUUID().toString());
		o.alipayRefund("2016090700000000", new BigDecimal("0.01"), head);
	}

	private void alipayRefund(String orderId, BigDecimal orderAmount, Head head) {
		String url = "https://openapi.alipay.com/gateway.do";
		String appId = CommonUtil.getProperties("alipay.app.id");
		String gowherePrivateKey = CommonUtil
				.getProperties("go.where.private.key");
		String alipayPulicKey = CommonUtil.getProperties("alipay.public.key");
		String format = "JSON";
		String signType = "RSA";
		String inputCharset = "UTF-8";
		String biz_content = "";
		String refund_reason = "正常退款";
		AlipayVo vo = new AlipayVo();
		vo.setOut_trade_no(orderId);
		vo.setRefund_amount(orderAmount.setScale(2).toString());
		vo.setRefund_reason(refund_reason);
		biz_content = CommonUtil.gson().toJson(vo);

		AlipayClient alipayClient = new DefaultAlipayClient(url, appId,
				gowherePrivateKey, format, inputCharset, alipayPulicKey,
				signType);
		AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
		request.setBizContent(biz_content);
		try {
			AlipayTradeRefundResponse response = alipayClient.execute(request);
			if (response != null) {
				log.info("requestId:" + head.getRequestId() + "订单号：" + orderId
						+ ",支付宝退款结果：" + CommonUtil.gson().toJson(response));
			} else {
				log.info("requestId:" + head.getRequestId() + "订单号：" + orderId
						+ ",支付宝退款结果未知");
			}
		} catch (Exception e) {
			log.error("requestId:" + head.getRequestId() + "订单号：" + orderId
					+ ",支付宝退款异常", e);
		}

	}

	private String signAlipayOrderInfo(OrderInfo orderInfo) {
		String partner = CommonUtil.getProperties("alipay.partner.id");
		String service = CommonUtil.getProperties("alipay.service.name");
		String sellerId = CommonUtil.getProperties("go.where.seller.id");
		String gowherePrivateKey = CommonUtil
				.getProperties("go.where.private.key");
		String inputCharset = "UTF-8";
		String signType = "RSA";
		String notifyUrl = CommonUtil.getProperties("alipay.notify.url");
		String outTradeNo = orderInfo.getOrderId();
		String subject = orderInfo.getActivityTitle();
		String paymentType = "1";
		String totalFee = CommonUtil.multiply(orderInfo.getOrderAmount(), 1)
				.toString();
		// 测试使用
		// totalFee = "0.01";
		String body = orderInfo.getActivityTitle();
		String signSource = createAlipaySignSource(service, partner,
				inputCharset, sellerId, notifyUrl, outTradeNo, subject,
				paymentType, totalFee, body, null, null);
		String sign = "";
		try {
			sign = AlipaySignature.rsaSign(signSource, gowherePrivateKey,
					inputCharset, signType);
			if (StringUtils.isNotBlank(sign)) {
				sign = URLEncoder.encode(sign, inputCharset);
			}
		} catch (AlipayApiException e) {
			log.error("支付宝rsa加密异常", e);
		} catch (UnsupportedEncodingException e) {
			log.error("sign进行urlencoder时异常", e);
		}

		String payParameter = createAlipaySignSource(service, partner,
				inputCharset, sellerId, notifyUrl, outTradeNo, subject,
				paymentType, totalFee, body, signType, sign);
		return payParameter;
	}

	private String createAlipaySignSource(String service, String partner,
			String inputCharset, String sellerId, String notifyUrl,
			String outTradeNo, String subject, String paymentType,
			String totalFee, String body, String signType, String sign) {
		TreeMap<String, Object> treeMap = new TreeMap<String, Object>(
				new Comparator<String>() {
					public int compare(String o1, String o2) {
						return o1.compareTo(o2);
					}
				});
		if (StringUtils.isNotBlank(service)) {
			treeMap.put("service", service);
		}
		if (StringUtils.isNotBlank(partner)) {
			treeMap.put("partner", partner);
		}
		if (StringUtils.isNotBlank(inputCharset)) {
			treeMap.put("_input_charset", inputCharset);
		}
		if (StringUtils.isNotBlank(sellerId)) {
			treeMap.put("seller_id", sellerId);
		}
		if (StringUtils.isNotBlank(notifyUrl)) {
			treeMap.put("notify_url", notifyUrl);
		}
		if (StringUtils.isNotBlank(outTradeNo)) {
			treeMap.put("out_trade_no", outTradeNo);
		}
		if (StringUtils.isNotBlank(subject)) {
			treeMap.put("subject", subject);
		}
		if (StringUtils.isNotBlank(paymentType)) {
			treeMap.put("payment_type", paymentType);
		}
		if (StringUtils.isNotBlank(totalFee)) {
			treeMap.put("total_fee", totalFee);
		}
		if (StringUtils.isNotBlank(body)) {
			treeMap.put("body", body);
		}
		if (StringUtils.isNotBlank(signType)) {
			treeMap.put("sign_type", signType);
		}
		if (StringUtils.isNotBlank(sign)) {
			treeMap.put("sign", sign);
		}

		StringBuilder sbu = new StringBuilder();
		Set<Map.Entry<String, Object>> set = treeMap.entrySet();
		Iterator<Map.Entry<String, Object>> it = set.iterator();
		Map.Entry<String, Object> entry = null;
		while (it.hasNext()) {
			entry = it.next();
			if (entry.getValue() != null) {
				if (StringUtils.isNotBlank(entry.getValue().toString())) {
					sbu.append(entry.getKey().toString());
					sbu.append("=");
					sbu.append("\"");
					sbu.append(entry.getValue().toString());
					sbu.append("\"");
					sbu.append("&");
				}
			}
		}
		String data = sbu.toString();
		data = data.substring(0, data.length() - 1);
		return data;
	}

	private String weichatOrderInfo(OrderInfo orderInfo) {
		String prepayId = "";
		String appid = CommonUtil.getProperties("wei.chat.app.id");
		String mchid = CommonUtil.getProperties("wei.chat.mch.id");
		String nonceStr = UUID.randomUUID().toString().replaceAll("-", "")
				.toUpperCase();
		String sign = "";
		String body = orderInfo.getActivityTitle();
		String outTradeNo = orderInfo.getOrderId();
		int totalFee = CommonUtil.multiply(orderInfo.getOrderAmount(), 10)
				.setScale(0, BigDecimal.ROUND_HALF_UP).intValue();
		// 测试使用
		// totalFee = 1;
		String spbillCreateIp = CommonUtil
				.getProperties("wei.chat.spbill.create.ip");
		String notifyUrl = CommonUtil.getProperties("wei.chat.notify.url");
		String tradeType = "APP";
		String signSourse = createWeichatSignSource(appid, mchid, nonceStr,
				body, outTradeNo, totalFee, spbillCreateIp, notifyUrl,
				tradeType);
		sign = MD5Util.MD5Encode(
				signSourse + "&key="
						+ CommonUtil.getProperties("wei.chat.md5.key"))
				.toUpperCase();
		log.info("签名字符串：" + signSourse + "&key="
				+ CommonUtil.getProperties("wei.chat.md5.key"));
		log.info("密文：" + sign);
		String url = CommonUtil.getProperties("wei.chat.prepay.url");
		String xmlData = requestXmlInfo(appid, mchid, nonceStr, body,
				outTradeNo, totalFee, spbillCreateIp, notifyUrl, tradeType,
				sign);
		String json = "";
		try {
			log.info("微信支付请求参数：" + xmlData);
			String xml = postWeichat(xmlData, url);
			log.info("微信支付返回参数" + xml);
			if (xml != null) {
				WeichatVo weichat = ParseWeichatXml.parse(xml);
				if (weichat != null) {
					if ("SUCCESS".equals(weichat.getReturnCode())
							&& "SUCCESS".equals(weichat.getResultCode())) {
						prepayId = weichat.getPrepayId();
						WeichatVo wvo = new WeichatVo();
						wvo.setReturnCode(weichat.getReturnCode());
						wvo.setResultCode(weichat.getResultCode());
						wvo.setAppid(appid);
						wvo.setPartnerId(mchid);
						wvo.setPrepayId(prepayId);
						wvo.setPackageStr("Sign=WXPay");
						wvo.setNonceStr(nonceStr);
						String timestamp = DateUtil.getSeconds();
						wvo.setTimestamp(timestamp);
						String sigsou = createWeichatPrepay(appid, mchid,
								nonceStr, prepayId, timestamp, "Sign=WXPay");
						String sgn = MD5Util.MD5Encode(sigsou + "&key="
								+ CommonUtil.getProperties("wei.chat.md5.key"));
						wvo.setSign(sgn);
						json = CommonUtil.gson().toJson(wvo);
					} else {
						WeichatVo wvo = new WeichatVo();
						wvo.setReturnCode(weichat.getReturnCode());
						wvo.setResultCode(weichat.getResultCode());
						wvo.setErrCode(weichat.getErrCode());
						wvo.setErrCodeDes(weichat.getErrCodeDes());
						json = CommonUtil.gson().toJson(wvo);
					}
				}
			}
		} catch (Exception e) {
			log.error("微信预支付访问异常", e);
		}

		return json;
	}

	private String createWeichatPrepay(String appid, String mchid,
			String nonceStr, String prepayId, String timestamp,
			String packageStr) {
		TreeMap<String, Object> treeMap = new TreeMap<String, Object>(
				new Comparator<String>() {
					public int compare(String o1, String o2) {
						return o1.compareTo(o2);
					}
				});
		if (StringUtils.isNotBlank(appid)) {
			treeMap.put("appid", appid);
		}
		if (StringUtils.isNotBlank(mchid)) {
			treeMap.put("partnerid", mchid);
		}
		if (StringUtils.isNotBlank(prepayId)) {
			treeMap.put("prepayid", prepayId);
		}
		if (StringUtils.isNotBlank(packageStr)) {
			treeMap.put("package", packageStr);
		}
		if (StringUtils.isNotBlank(nonceStr)) {
			treeMap.put("noncestr", nonceStr);
		}
		if (StringUtils.isNotBlank(timestamp)) {
			treeMap.put("timestamp", timestamp);
		}
		StringBuilder sbu = new StringBuilder();
		Set<Map.Entry<String, Object>> set = treeMap.entrySet();
		Iterator<Map.Entry<String, Object>> it = set.iterator();
		Map.Entry<String, Object> entry = null;
		while (it.hasNext()) {
			entry = it.next();
			if (entry.getValue() != null) {
				if (StringUtils.isNotBlank(entry.getValue().toString())) {
					sbu.append(entry.getKey().toString());
					sbu.append("=");
					sbu.append(entry.getValue().toString());
					sbu.append("&");
				}
			}
		}
		String data = sbu.toString();
		data = data.substring(0, data.length() - 1);
		return data;
	}

	private String postWeichat(String xml, String url) {
		try {
			HttpURLConnection conn = (HttpURLConnection) new URL(url)
					.openConnection();
			// 加入数据
			conn.setRequestMethod("POST");
			conn.setDoOutput(true);

			BufferedOutputStream buffOutStr = new BufferedOutputStream(conn
					.getOutputStream());
			buffOutStr.write(xml.getBytes());
			buffOutStr.flush();
			buffOutStr.close();

			// 获取输入流
			BufferedReader reader = new BufferedReader(new InputStreamReader(
					conn.getInputStream()));
			String line = null;
			StringBuffer sb = new StringBuffer();
			while ((line = reader.readLine()) != null) {
				sb.append(line);
			}
			return sb.toString();
		} catch (Exception e) {
			log.error("向微信发起预支付请求时出现异常", e);
		}
		return null;
	}

	private String requestXmlInfo(String appid, String mchid, String nonceStr,
			String body, String outTradeNo, int totalFee,
			String spbillCreateIp, String notifyUrl, String tradeType,
			String sign) {
		StringBuilder sb = new StringBuilder();
		sb.append("<xml>");
		sb.append("<appid>");
		sb.append(appid);
		sb.append("</appid>");
		sb.append("<body>");
		sb.append(body);
		sb.append("</body>");
		sb.append("<mch_id>");
		sb.append(mchid);
		sb.append("</mch_id>");
		sb.append("<nonce_str>");
		sb.append(nonceStr);
		sb.append("</nonce_str>");
		sb.append("<notify_url>");
		sb.append(notifyUrl);
		sb.append("</notify_url>");
		sb.append("<out_trade_no>");
		sb.append(outTradeNo);
		sb.append("</out_trade_no>");
		sb.append("<spbill_create_ip>");
		sb.append(spbillCreateIp);
		sb.append("</spbill_create_ip>");
		sb.append("<total_fee>");
		sb.append(totalFee);
		sb.append("</total_fee>");
		sb.append("<trade_type>");
		sb.append(tradeType);
		sb.append("</trade_type>");
		sb.append("<sign>");
		sb.append(sign);
		sb.append("</sign>");
		sb.append("</xml>");

		return sb.toString();
	}

	private String createWeichatSignSource(String appid, String mchid,
			String nonceStr, String body, String outTradeNo, int totalFee,
			String spbillCreateIp, String notifyUrl, String tradeType) {
		TreeMap<String, Object> treeMap = new TreeMap<String, Object>(
				new Comparator<String>() {
					public int compare(String o1, String o2) {
						return o1.compareTo(o2);
					}
				});
		if (StringUtils.isNotBlank(appid)) {
			treeMap.put("appid", appid);
		}
		if (StringUtils.isNotBlank(mchid)) {
			treeMap.put("mch_id", mchid);
		}
		if (StringUtils.isNotBlank(nonceStr)) {
			treeMap.put("nonce_str", nonceStr);
		}
		if (StringUtils.isNotBlank(body)) {
			treeMap.put("body", body);
		}
		if (StringUtils.isNotBlank(notifyUrl)) {
			treeMap.put("notify_url", notifyUrl);
		}
		if (StringUtils.isNotBlank(outTradeNo)) {
			treeMap.put("out_trade_no", outTradeNo);
		}
		if (totalFee != 0) {
			treeMap.put("total_fee", totalFee);
		}
		if (StringUtils.isNotBlank(spbillCreateIp)) {
			treeMap.put("spbill_create_ip", spbillCreateIp);
		}
		if (StringUtils.isNotBlank(tradeType)) {
			treeMap.put("trade_type", tradeType);
		}

		StringBuilder sbu = new StringBuilder();
		Set<Map.Entry<String, Object>> set = treeMap.entrySet();
		Iterator<Map.Entry<String, Object>> it = set.iterator();
		Map.Entry<String, Object> entry = null;
		while (it.hasNext()) {
			entry = it.next();
			if (entry.getValue() != null) {
				if (StringUtils.isNotBlank(entry.getValue().toString())) {
					sbu.append(entry.getKey().toString());
					sbu.append("=");
					sbu.append(entry.getValue().toString());
					sbu.append("&");
				}
			}
		}
		String data = sbu.toString();
		data = data.substring(0, data.length() - 1);
		return data;
	}

	/**
	 * 创建订单
	 * 
	 * @param vo
	 * @param customerId
	 * @param activityId
	 * @param courseId
	 * @param activityType
	 * @param activityInfo
	 * @param courseInfo
	 * @param orderId
	 * @return
	 */
	private OrderInfo createOrder(OrderVo vo, String customerId,
			ActivityInfo activityInfo, CourseInfo courseInfo, String orderId,
			Integer stock) {
		OrderInfo orderInfo = new OrderInfo();
		orderInfo.setOrderId(orderId);
		orderInfo.setCustomerId(customerId);
		orderInfo.setActivityId(vo.getActivityId());
		orderInfo.setCourseId(vo.getCourseId());
		if (activityInfo != null) {
			orderInfo.setActivityType(activityInfo.getActivityType());
		} else {
			orderInfo.setActivityType(Constant.ACTIVITY_TYPE_BUY);
		}
		if (StringUtils.isNotBlank(vo.getActivityId())) {
			orderInfo.setBigClassId(activityInfo.getBigClassId());
			orderInfo.setSmallClassId(activityInfo.getSmallClassId());
			orderInfo.setSmallClassSubId(activityInfo.getSmallClassSubId());
			ActivityInfo ac = new ActivityInfo();
			ac.setActivityId(vo.getActivityId());
			Integer currentStock = CommonUtil.sub(stock, vo.getPersonNum());
			ac.setStock(currentStock);
			activityService.update(ac);
		}
		if (StringUtils.isNotBlank(vo.getCourseId())) {
			orderInfo.setBigClassId(courseInfo.getTopicId());
			orderInfo.setSmallClassId(courseInfo.getCourseId());
			orderInfo.setSmallClassSubId(courseInfo.getCourseSubId());
			CourseInfo ci = new CourseInfo();
			ci.setCourseId(vo.getCourseId());
			Integer currentStock = CommonUtil.sub(stock, vo.getPersonNum());
			ci.setCourseLimit(currentStock);
			courseService.update(ci);
		}
		orderInfo.setOrderAmount(vo.getOrderAmount());
		orderInfo.setPersonNum(vo.getPersonNum());
		if (vo.getOrderAmount().intValue() == 0) {
			orderInfo.setPayStatus(Constant.PAY_STATUS_PAYED);
			orderInfo.setOrderStatus(Constant.ORDER_STATUS_SUCCESS);
		} else {
			orderInfo.setPayStatus(Constant.PAY_STATUS_NOT_PAY);
			orderInfo.setOrderStatus(Constant.ORDER_STATUS_PROGRESS);
		}
		return orderInfo;
	}

}
